<extend name="./public/frame.html"/>
<block name="content">
    <style>
        .layui-form-label {
            width: 10%;
        }

        .layui-input-block {
            margin-left: 12%;
        }
    </style>
    <form class="layui-form layui-form-pane1" action="{:url('version/edit')}" method="post" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{$data.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">应用类型</label>
            <div class="layui-input-block" style="padding-top: 10px">
                {$type[$data.type]}
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">安卓版本号</label>
            <div class="layui-input-block">
                <input type="text" name="andriod_num" value="{$data.andriod_num}" lay-verify="required" required placeholder="安卓版本号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">安卓小版本号</label>
            <div class="layui-input-block">
                <input type="text" name="andriod_minor_version" value="{$data.andriod_minor_version}" lay-verify="required|number" placeholder="安卓小版本号"
                       autocomplete="off" class="layui-input" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">安卓最低向下兼容版本号</label>
            <div class="layui-input-block">
                <!--<select name="andriod_min_num" lay-verify="required">-->
                <select name="andriod_min_num">
                    <option value="">请选择</option>
                    <volist name="historyVersion" id="v">
                        <option <if condition="$data['andriod_min_num'] eq $v['andriod_num']"> selected="selected" </if>  value="{$v['andriod_num']}">{$v["andriod_num"]}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">安卓安装软件</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">安卓下载url</label>
            <div class="layui-input-block">
                <input type="text" name="andriod_url" class="layui-input" value="{$data.andriod_url}">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">请填安卓更新的内容</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="andriod_content">{$data.andriod_content}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否提醒升级（Andriod）</label>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="is_remind_andriod" id="is_remind_andriod" lay-filter="is_remind_andriod">
                    <option value="0" <?php if($data['is_remind_andriod'] == 0):?>selected<?php endif;?>>否</option>
                    <option value="1" <?php if($data['is_remind_andriod'] == 1):?>selected<?php endif;?>>是</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item andriod_status" <?php if($data['is_remind_andriod'] != 1):?>style="display:none;"<?php endif;?>>
            <label class="layui-form-label">安卓是否强迫升级</label>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="andriod_status">
                    <option value="0" <if condition="$data.andriod_status eq 0">selected</if>>否</option>
                    <option value="1" <if condition="$data.andriod_status eq 1">selected</if>>是</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">安卓小版本是否强迫升级</label>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="force_update_minor_version" id="force_update_minor_version" lay-filter="">
                    <option value="0" <if condition="$data.force_update_minor_version eq 0">selected</if>>否</option>
                    <option value="1" <if condition="$data.force_update_minor_version eq 1">selected</if>>是</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">IOS版本号</label>
            <div class="layui-input-block">
                <input type="text" name="ios_num" autocomplete="off" lay-verify="required" class="layui-input" value="{$data.ios_num}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">IOS最低向下兼容版本号</label>
            <div class="layui-input-block">
                <!--<select name="ios_min_num" lay-verify="required">-->
                <select name="ios_min_num">
                    <option value="">请选择</option>
                    <volist name="historyVersion" id="v">
                        <option <if $data['ios_min_num']==$v["ios_num"]> selected="selected" </if>  value="{$v['ios_num']}">{$v["ios_num"]}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">IOS下载url</label>
            <div class="layui-input-block">
                <input type="text" name="ios_url" autocomplete="off" lay-verify="url" class="layui-input" value="{$data.ios_url}">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">请填IOS更新的内容</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="ios_content">{$data.ios_content}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否提醒升级（IOS）</label>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="is_remind_ios" id="is_remind_ios" lay-filter="is_remind_ios">
                    <option value="0" <?php if($data['is_remind_ios'] == 0):?>selected<?php endif;?>>否</option>
                    <option value="1" <?php if($data['is_remind_ios'] == 1):?>selected<?php endif;?>>是</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item ios_status" <?php if($data['is_remind_ios'] != 1):?>style="display:none;"<?php endif;?>>
            <label class="layui-form-label">IOS是否强迫升级</label>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="ios_status">
                    <option value="0" <if condition="$data.ios_status eq 0">selected</if>>否</option>
                    <option value="1" <if condition="$data.ios_status eq 1">selected</if>>是</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item is_grey">
            <label class="layui-form-label">是否灰度更新</label>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="is_grey" id="is_grey" lay-filter="is_grey">
                    <option value="0" >否</option>
                    <option value="1" <if $data['is_grey']==1> selected="selected" </if>>是</option>
                </select>
            </div>
        </div>
<!--        <div class="layui-form-item inputModel" <if $data['is_grey']!=1> style="display:none;" </if>>-->
<!--            <label class="layui-form-label">导入手机号码</label>-->
<!--            <div class="layui-input-inline" style="width: 200px;">-->
<!--                <button type="button" class="layui-btn uploads" >导入号码</button>-->
<!--                <a href="<?php echo $url;?>" style="color: green;margin-left: 20px;">电话号码模板 - 下载</a>-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="layui-form-item inputModel" <if $data['is_grey']!=1> style="display:none;" </if>>-->
<!--            <table class="layui-table">-->
<!--                <tr>-->
<!--                    <td style="text-align: center;width: 15%">补发用户手机号</td>-->
<!--                    <td>-->
<!--                        <table class="layui-table inside_price">-->
<!--                            <tr>-->
<!--                                <td>-->
<!--                                    <input type="text" name="phone[]" id="phone_01" value="" lay-verify="required" placeholder="用户手机号码" class="layui-input" style="width: 200px;float: left;" onkeyup="num(this)">-->
<!--                                    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="look" style="width: 30px;float: left;margin-top: 8px;margin-left: 10px;" onclick="insidePrice()">+</a>-->
<!--                                </td>-->
<!--                            </tr>-->
<!--                        </table>-->
<!--                    </td>-->
<!--                </tr>-->
<!--            </table>-->
<!--        </div>-->
        <if $data['type']==1>
        <div class="layui-form-item inputModel" <if $data['is_grey']!=1> style="display:none;" </if>>
            <label class="layui-form-label">uer_ids</label>
            <div class="layui-input-block">
                <textarea  class="layui-textarea"  name="uer_ids"><?php echo $data['uer_ids']; ?></textarea>
            </div>
        </div>
        </if>
        <if $data['type']==2||$data['type']==3>
        <div class="layui-form-item inputModel" <if $data['is_grey']!=1> style="display:none;" </if>>
            <label class="layui-form-label">driver_id</label>
            <div class="layui-input-block">
                <textarea  class="layui-textarea" name="driver_ids"><?php echo $data['driver_ids']; ?></textarea>
            </div>
        </div>
        </if>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <div class="fadeBg"></div>
    <div class="fadeCont"style="width: 20%;left: 40%;top: 30%">
        <div class="fadeBox upload">
            <img src="__WEB__/images/uploading.gif" style="width: 30%;height: auto">
            <p style="font-size: 12px;margin-bottom: 3px;">处理中，请稍等……</p>
        </div>
    </div>
    <script>
        layui.use(['laydate', 'upload','form'], function () {
            var laydate = layui.laydate
                ,upload = layui.upload
                ,form = layui.form
            ;
            upload.render({ //允许上传的文件后缀
                elem: '#test3'
                ,auto:false
                ,field:'apk'
                ,accept: 'file' //普通文件
                ,exts: 'apk' //只允许上传安装文件
                ,choose: function(obj){
                    obj.preview(function(index, file, result){
                        var str = "<span style='margin-left: 5px'>"+file.name+"</span>";
                        $('#test3').after(str);
                    });
                }
            });
            upload.render({
                elem: '.uploads'//这个就等同于点击
                ,accept: 'file'
                ,url: '/admin/Upload/excelUpload'
                ,done:  function(res){ //上传后的回调
                    if(res.status == 1){
                        layer.msg('导入成功',{icon: 1});
                        var html = '';
                        var i  = $('.inside_price tr').length;
                        $.each(res.CHILD, function() {
                            i++;
                            if(i == 2){
                                $("#phone_01").val(this);
                            }else{
                                html += '<tr>\n' +
                                    '      <td>\n' +
                                    '          <input type="text" name="phone[]" id="phone_0'+i+'" value="'+this+'" placeholder="用户手机号码" class="layui-input" style="width: 200px;float: left;" onkeyup="num(this)">\n' +
                                    '          <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="look" style="width: 30px;margin-top: 8px;margin-left: 10px;" onclick="reduceInsidePrice(this)">-</a>\n' +
                                    '      </td>\n' +
                                    '</tr>';
                            }
                        })
                        $(".inside_price").append(html);
                    }else{
                        layer.msg(res.msg);
                    }
                }
                ,error: function(e){
                    console.log(e)
                }
            });
            //安卓提醒是否升级
            form.on('select(is_remind_andriod)', function(data){
                if(data.value == 1){
                    $(".andriod_status").css('display','block');
                }else{
                    $(".andriod_status").css('display','none');
                }
            });
            //IOS提醒是否升级
            form.on('select(is_remind_ios)', function(data){
                if(data.value == 1){
                    $(".ios_status").css('display','block');
                }else{
                    $(".ios_status").css('display','none');
                }
            });
            //灰度更新
            form.on('select(is_grey)', function(data){
                if(data.value == 1){
                    $(".inputModel").css('display','block');
                }else{
                    $(".inputModel").css('display','none');
                }
            });
            //监听提交
            form.on('submit(submit)', function (data) {
                $('.fadeBg').show();
                $('.fadeCont .upload').show();
                $('.fadeCont').show();
            });
        });
        //验证只能输入正确的手机号码
        function num(object) {
            var value   = object.value;
            var id      = object.id;
            if (isNaN(value)){
                layer.msg('请输入正确的数字',{icon: 5});
                $("#"+id).val('');
                return false;
            }
        }

        function insidePrice() {
            var i  = $('.inside_price tr').length;
            console.log(i)
            i++;
            var html = '<tr>\n' +
                '           <td>\n' +
                '                <input type="text" name="phone[]" id="phone_0'+i+'" value="" placeholder="用户手机号码" class="layui-input" style="width: 200px;float: left;" onkeyup="num(this)">\n' +
                '                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="look" style="width: 30px;margin-top: 8px;margin-left: 10px;" onclick="reduceInsidePrice(this)">-</a>\n' +
                '           </td>\n' +
                '       </tr>';
            $(".inside_price").append(html);
        }
    </script>
</block>
